<template>
  <el-dialog
    destroy-on-close
    title="审批记录"
    :close-on-click-modal="false"
    :visible.sync="Lvisible"
    width="1200px"
    @open="onSearch"
    @close="onClose"
  >
    <span>
      <el-table
        :data="tableData"
        v-loading="loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        height="300"
        stripe
        border
        style="width: 100%"
      >
        <!-- <el-table-column :resizable="false" prop="describe" label="模块" min-width="100" /> -->
        <el-table-column :resizable="false" prop="checkdis" label="审批级次" width="180" />
        <el-table-column :resizable="false" prop="checkusername" label="审批人" width="180" />
        <el-table-column :resizable="false" prop="checkdatetime" label="审批时间" width="180" />
        <el-table-column :resizable="false" prop="checktypestr" label="状态" width="150" />
        <el-table-column :resizable="false" prop="note" label="说明" min-width="100">
          <template slot-scope="scope">
            <div v-html="scope.row.note"></div>
          </template>
        </el-table-column>
      </el-table>
    </span>
  </el-dialog>
</template>

<script>
import { ExamHistoryget } from '@/api/Approval/index'
import { mapState, mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters(['approve']),
    documentid() {
      return this.approve.documentid
    },
    visible() {
      return this.approve.visible
    },
    modelcode() {
      return this.approve.modelcode
    }
  },
  data() {
    return {
      tableData: [],
      loading: true,
      Lvisible: this.visible
    }
  },
  watch: {
    approve(newVal) {
      this.Lvisible = newVal.visible
    }
  },
  methods: {
    onSearch() {
      if (this.documentid == '' || this.documentid == undefined || this.documentid == null) {
        this.$message.error('获取审批记录失败,请重试')
        return this.onClose()
      }
      this.loading = true
      ExamHistoryget({ modelcode: this.modelcode, documentid: this.documentid })
        .then(result => {
          if (result.success) {
            var content = result.content || []
            content.forEach(item => {
              if (item.note != null) {
                item.note = item.note.replace(/\\n/g, '<br/>')
                item.note = item.note.replace(/\n/g, '<br/>')
              }
            })
            this.tableData = content
            this.loading = false
          } else {
            this.$message.error(result.message)
            this.$message.error('获取审批记录失败,请重试')
            return this.onClose()
            this.loading = false
          }
        })
        .catch(err => {
          this.$message.error('获取审批记录失败,请重试')
          return this.onClose()
          this.loading = false
        })
    },
    onClose(type) {
      this.loading = true
      this.tableData = []
      if (type == 1) {
        this.$approveClose(true)
      }
    }
  }
}
</script>

<style></style>
